package org.parademo.web.model;

import org.parademo.model.UserEntity;
import org.parademo.web.controller.util.ViewFormatterUtil;

import java.text.SimpleDateFormat;
import java.util.Date;

public class UserView {
    private Long id;
    private String userName;
    private String firstName;
    private String lastName;
    private String joinDate;
    private String birthDate;
    private String address;

    public UserView() {
    }

    public UserView(UserEntity userEntity) {
        this.id = userEntity.getId();
        this.userName = userEntity.getUserName();
        this.firstName = userEntity.getFirstName();
        this.lastName = userEntity.getLastName();
        this.joinDate = formatDate(
                userEntity.getJoinDate()
        );
        this.birthDate = formatDate(
                userEntity.getBirthDate()
        );
        this.address = ViewFormatterUtil.formatAddress(
                userEntity.getAddress()
        );
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public String getJoinDate() {
        return joinDate;
    }

    public void setJoinDate(String joinDate) {
        this.joinDate = joinDate;
    }

    public String getBirthDate() {
        return birthDate;
    }

    public void setBirthDate(String birthDate) {
        this.birthDate = birthDate;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    private String formatDate(Date date) {
        return new SimpleDateFormat("dd.MM.yyyy").format(date);
    }
}
